finding local maximum and minimum point when function is rational